<?php

class Application_Model_PayCodeOrder extends Application_Model_DomainObject implements Application_Model_PayInterface {

    protected $_id; //序号
    protected $_uid; //用户ID	
    protected $_userName; //用户名	
    protected $_money; //金额        
    protected $_cardid; //授权卡序号	
    protected $_cardno; //授权卡号   	
    protected $_verifyCode; //授权密码
    protected $_typeid; //所属类型	
    protected $_cardType; //卡类型	
    protected $_createTime; //创建时间	
    protected $_payTime; //付款时间        
    protected $_payType; //付款类型
    protected $_url; //相关地址
    protected $_state; //状态         0：未付款 5、受理中 10：已付款  20：待充值  30：充值完成 100:撤消
    protected $_remark; //备注
    protected $_replyuid; //回复用户序号
    protected $_replyTime; //回复时间
    protected $_replynote; //回复内容

    /**
     * 返回数据持久化对象
     * @return Application_Model_PayCodeCard
     */

    protected static function getDb() {
        return new Application_Model_DbTable_PayCodeOrder();
    }

    public static function getByUid($uid) {
        $result = Application_Model_PayCodeOrder::getDb()->getByUid($uid);
        return $result;
    }

    public static function getByFilter($inid, $memberId, $startTime, $endTime, $status, $count, $offset, $cardtype) {
        $where = array();
        $and = '';


        if ($memberId != NULL) {
            $where[$and . ' uid = '] = $memberId;
            $and = ' and ';
        }

        if ($memberId != NULL) {
            $where[$and . ' cardtype = '] = $cardtype;
            $and = ' and ';
        }

        if ($status != NULL) {
            $where[$and . ' state = '] = $status;
            $and = ' and ';
        }

        if ($startTime != NULL) {
            $where[$and . ' createTime >= '] = $startTime;
            $and = ' and ';
        }

        if ($endTime != NULL) {
            $where[$and . ' createTime <= '] = $endTime;
            $and = ' and ';
        }

        return Application_Model_PayCodeOrder::getDb()->queryPage($where, 'id desc ', $count, $offset);
    }
    
    public function getUserId(){
        return $this->_uid;
    }

    public function getMoney() {
        return $this->_money;
    }

    public function getPayName() {
        return '悠奇-支付宝充值码';
    }
    
    public function getPayCommen() {
        return "支付宝充值码流水号：".$this->_id;
    }
    
    public function isRepeatPay() {
        if($this->_status == 0){
            return true;
        } 
        return false;
    }

    public function setPaid() {
        $this->_state = 10;
    }

    public function getBillNo() {
        return $this->_id;
    }
    
    public function getPayDescription() {
        return '支付宝充值码';
    }
    
    public function canPay($userId) {
        if($this->_state != 0)
            return FALSE;
        if($this->_uid != $userId)
            return FALSE;
        return TRUE;
    }
}